package com.jiaertangshi.jiaer.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jiaertangshi.jiaer.dto.Shop;
import com.jiaertangshi.jiaer.dto.vo.GetNearbyShopByPage;
import com.jiaertangshi.jiaer.dto.vo.ShopFood;
import com.jiaertangshi.jiaer.service.ShopService;

/**
 * @ClassName: ShopController
 * @Description: ShopController
 * @author zfy
 * @date 2019年1月14日
 *
 */
@RequestMapping("/shop")
@RestController
public class ShopController {

	@Autowired
	ShopService  shopService;
	
	/*
	 *Demo  无效
	 */
	@RequestMapping(value = "/getOneShop", method = RequestMethod.GET)
	public   Shop   getAllShop(){
		return 	shopService.getAllShop();
	}
	
	
	
	/*
	 * 根据地理位置获取附近的商家（分页）
	 */
	@RequestMapping(value = "/getNearbyShop", method = RequestMethod.GET)
	public   List<GetNearbyShopByPage>   getNearbyShopByPage(
			@RequestParam(defaultValue = "1") Integer page, 
			@RequestParam(defaultValue = "10") Integer size,
			@RequestParam(value = "longitude",defaultValue = "", required=false) String longitude,
			@RequestParam(value = "latitude", defaultValue = "",required=false) String latitude,
			@RequestParam(value = "xianshiqu", defaultValue = "",required=false) String xianshiqu,
			@RequestParam(value = "shopType",defaultValue = "0", required=false) Integer shopType) {
		
			double  longitude1=Double.parseDouble(longitude);
			double  latitude1=Double.parseDouble(latitude);
			List<GetNearbyShopByPage>  shops =  	shopService.getNearbyShopByPage(page,size,longitude1,latitude1,xianshiqu,shopType);
		return 	shops;
	}
	
	
	
	/*
	 * 根据地理位置搜索附近的商家（分页）
	 */
	@RequestMapping(value = "/serachNearbyShop", method = RequestMethod.GET)
	public   List<GetNearbyShopByPage>   serachNearbyShop(
			@RequestParam(defaultValue = "1") Integer page, 
			@RequestParam(defaultValue = "10") Integer size,
			@RequestParam(value = "longitude",defaultValue = "", required=false) String longitude,
			@RequestParam(value = "latitude", defaultValue = "",required=false) String latitude,
			@RequestParam(value = "serach", defaultValue = "",required=false) String serach) {
			double  longitude1=Double.parseDouble(longitude);
			double  latitude1=Double.parseDouble(latitude);
			List<GetNearbyShopByPage>  shops =  	shopService.serachNearbyShop(page,size,longitude1,latitude1,serach);
		return 	shops;
	}
	
	
	/*
	 * 根据 shopid获取此商家的菜单信息
	 */
	@RequestMapping(value = "/allFoodByShop", method = RequestMethod.GET)
	public   List<ShopFood>   allFoodByShop(@RequestParam(value = "shopId", required = true) String shopId){
		 List<ShopFood>  sfs=new  ArrayList<ShopFood>();
		 sfs =  	shopService.getAllFoodByShop(shopId);
		 return 	sfs;
	}
	
	
}
